package formatter;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;
import banking.Account;

public class FormFactory {
	private Map<String, IStatementFormater> formatter;
	
	public FormFactory(Account account){
		formatter = new Hashtable<String, IStatementFormater>();
		
		Properties props = new Properties();
		
		FileInputStream in;
		try {
			in = new FileInputStream("iBank/props/local.properties");
			props.load(in);
		} catch (IOException e) {
			e.printStackTrace();
		}
		String plainText = props.getProperty("text/plain");
		String plainHTML = props.getProperty("text/html");
		TextPlainFormatter plain = null;
		TextHtmlFormatter html = null;
		try {
			plain = (TextPlainFormatter) Class.forName(plainText).newInstance();
			plain.addData(account);
			html = (TextHtmlFormatter) Class.forName(plainHTML).newInstance();
			html.addData(account);
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println("No Class");
		} 

		formatter.put("text/plain", plain);
		formatter.put("text/html", html);
	}
	
	public IStatementFormater getStatementFormatter(String mimeType){
		return formatter.get(mimeType);
	}
}
